#ifndef LOCKFREE_HASHTABLE_H
#define LOCKFREE_HASHTABLE_H

#include "../atomic/tagged_ptr.h"
#include <stddef.h>
#include <stdbool.h>

// 哈希表节点
typedef struct hash_node {
    void* key;
    void* value;
    struct hash_node* next;
    size_t hash;
} hash_node_t;

// 哈希表桶
typedef struct {
    atomic_tagged_ptr_t head;
} hash_bucket_t;

// 哈希表
typedef struct {
    hash_bucket_t* buckets;
    size_t bucket_count;
    size_t (*hash_func)(const void* key);
    bool (*key_equals)(const void* key1, const void* key2);
} hashtable_t;

// 初始化哈希表
bool hashtable_init(hashtable_t* table, 
                   size_t bucket_count,
                   size_t (*hash_func)(const void* key),
                   bool (*key_equals)(const void* key1, const void* key2));

// 销毁哈希表
void hashtable_destroy(hashtable_t* table);

// 插入键值对
bool hashtable_put(hashtable_t* table, void* key, void* value);

// 获取值
void* hashtable_get(hashtable_t* table, const void* key);

// 删除键值对
bool hashtable_remove(hashtable_t* table, const void* key);

// 获取大小
size_t hashtable_size(hashtable_t* table);

#endif // LOCKFREE_HASHTABLE_H 